//
//  NormalLineChartView.swift
//  TimeBoat
//
//  Created by bo wang on 2022/8/26.
//  Copyright © 2022 Time Boat. All rights reserved.
//

import UIKit
import Charts

class NormalLineChartView: LineChartView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupChartView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupChartView()
    }
    
    func setupChartView() {
        
        let scale = UIScreen.main.nativeScale
        
//        chartView.gridBackgroundColor
//        chartView.drawGridBackgroundEnabled
        
//        chartView.borderColor
//        chartView.borderLineWidth
//        chartView.drawBordersEnabled
        
        // 用户交互
        dragEnabled = false
//        chartView.dragXEnabled
//        chartView.dragYEnabled
        setScaleEnabled(false)
//        chartView.scaleXEnabled
//        chartView.scaleYEnabled
        doubleTapToZoomEnabled = false
        highlightPerDragEnabled = false
        pinchZoomEnabled = false
        autoScaleMinMaxEnabled = false
        dragDecelerationEnabled = false
//        chartView.dragDecelerationFrictionCoef
        
        // 不显示图例
        legend.enabled = false
        
        noDataText = "没有数据"
        noDataFont = UIFont.systemFont(ofSize: 14)
        noDataTextColor = HEX(0x3F4870)!
        noDataTextAlignment = .center
        
        drawMarkers = false
        
        leftAxis.enabled = true
        leftAxis.drawBottomYLabelEntryEnabled = true
        leftAxis.drawTopYLabelEntryEnabled = true
        leftAxis.drawZeroLineEnabled = true
        leftAxis.zeroLineColor = HEX(0x707070, alpha: 0.1)
        leftAxis.zeroLineWidth = 1
        leftAxis.spaceTop = 0.25
        leftAxis.spaceBottom = 0.25
        leftAxis.axisMinimum = 0
//        leftAxis.labelAlignment = .left
//        leftAxis.labelXOffset = -12
//        leftAxis.minWidth = 30
//        leftAxis.maxWidth = 30
        leftAxis.labelFont = UIFont.systemFont(ofSize: 12, weight: .medium)
        leftAxis.labelTextColor = HEX(0x3F4870)!
        leftAxis.axisLineColor = .clear
//        leftAxis.labelCount = 3
        leftAxis.drawGridLinesEnabled = true
        leftAxis.gridLineWidth = 1
        leftAxis.gridColor = HEX(0x707070, alpha: 0.1)!
        
        rightAxis.enabled = false
        
        xAxis.labelPosition = .bottom
        xAxis.labelFont = UIFont.systemFont(ofSize: 10)
        xAxis.labelTextColor = .black
        xAxis.axisLineColor = .clear
        xAxis.axisLineWidth = 1
        xAxis.drawGridLinesEnabled = false
        
        extraLeftOffset = 10
        extraRightOffset = 20
    }
}
